const mongoose = require('mongoose')

// 连接mongdb 使用immooc这个集合
const DB_URL ='mongodb://localhost:27017/immooc-chat'
mongoose.connect(DB_URL)
mongoose.connection.on('connected', () => {
    console.log('sb')
});
const models={
    user:{
        'user':{'type':String,require:true},
        'pwd':{'type':String,require:true},
        'type':{'type':String,require:true},
        'salt':{'type':String,require:true},
        'avatar':{'type':String},
		// 个人简介或者职位简介
		'desc':{'type':String},
		// 职位名
        'title':{'type':String},
    
        'company':{'type':String},
        'money':{'type':String},
    },
    chat:{
        'chatid':{'type':String,require:true},
        'from':{'type':String,require:true},
        'to':{'type':String,require:true},
        'read':{'type':Boolean,default:false},
        'avatar':{'type':String,require:true},
        'from_name':{'type':String,require:true},
        'msg_from':{'type':String,require:true},
        'msg_to':{'type':String,require:true},
        'to_name':{'type':String,require:true},
        'content':{'type':String,require:true,default:''},
        'create_time':{'type':Number,default:Date.now},
    }
}

for(let i in models){
    mongoose.model(i,new mongoose.Schema(models[i]))
}

module.exports={
    getModels:function (name) {
        return mongoose.model(name)
    }
}